import { fileURLToPath, URL } from 'node:url'
// @ts-ignore
import postCssPxToRem from "postcss-pxtorem"
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig({
  plugins: [
      vue(),
    Components({
      resolvers: [VantResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions: [".ts", ".vue", ".js", ".jsx", ".tsx"]
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    proxy: {
      '/wangyi': {
        target: 'https://m.you.163.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/wangyi/, ''),
      },
      '/qiantai':{
        target: 'http://sph-h5-api.atguigu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/qiantai/, ''),
      }
    }
  }
})
